package com.cee.controller;


import com.cee.common.result.Result;
import com.cee.dto.TwoTypeDTO;
import com.cee.service.OneTwoTypeService;
import com.cee.service.TwoTypeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/twoType")
public class TwoTypeController {

    @Autowired
    private OneTwoTypeService oneTwoTypeService;

    @Autowired
    private TwoTypeService twoTypeService;

    @PostMapping("/list")
    public Result getList(@RequestBody TwoTypeDTO twoTypeDTO){
        PageInfo pageInfo = twoTypeDTO.getPageInfo();
        Page<TwoTypeDTO> page = PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());

        oneTwoTypeService.getTwoPageByDTO(twoTypeDTO);
        return Result.ok(new PageInfo<>(page));
    }


//    @GetMapping("/delete")
//    public Result deleteOneType(Integer id){
//
//        oneTypeService.deleteOneType(id);
//        return Result.ok();
//    }
//
    @PostMapping ("/add")
    public Result addTwoType(@RequestBody TwoTypeDTO twoTypeDTO){

        twoTypeService.saveTwoType(twoTypeDTO);
        return Result.ok();
    }


    @GetMapping ("/delete")
    public Result deleteTwoType(Integer id){

        oneTwoTypeService.deleteOneTwoType(id);
        return Result.ok();
    }

}
